<template>
  <el-card class="box-card">
    <el-form
      :inline="true"
      :disabled="!isForbiddenForm"
      class="demo-form-inline"
    >
      <el-form-item label="一级分类">
        <!-- <el-select v-model="categoryStore.category1Id" placeholder="请选择"> -->
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option
            v-for="c1 in categoryStore.category1List"
            :label="c1.name"
            :value="c1.id"
            :key="c1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option
            v-for="c2 in categoryStore.category2List"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="categoryStore.category3Id" placeholder="请选择">
          <el-option
            v-for="c3 in categoryStore.category3List"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          />
        </el-select>
      </el-form-item> </el-form
  ></el-card>
</template>
<script lang="ts">
export default {
  name: "CategorySelector",
  props: {
    isForbiddenForm: {
      type: Boolean,
    },
  },
}
</script>
<script lang="ts" setup>
import { reactive, onMounted, computed } from "vue"
// import { reqGetCategory1ListData } from "@/api/product/category"
import { useCategoryListStore } from "@/stores/categoryList"
const categoryStore = useCategoryListStore()

onMounted(async () => {
  // const result = await reqGetCategory1ListData()
  // console.log("一级分类", result)
  // 获取一级分类
  categoryStore.getCategory1ListData()
})
// 使用计算属性,传入一级id获取二级分类
const category1Id = computed<number>({
  get() {
    return categoryStore.category1Id as number
  },
  set(value) {
    categoryStore.getCategory2ListData(value)
  },
})
// 使用计算属性,传入二级id获取三级分类
const category2Id = computed<number>({
  get() {
    return categoryStore.category2Id as number
  },
  set(value) {
    categoryStore.getCategory3ListData(value)
  },
})
// 使用计算属性,传入三级id
const category3Id = computed<number>({
  get() {
    return categoryStore.category3Id as number
  },
  set(val) {
    categoryStore.setCategory3Id(val)
  },
})
</script>
